package com.matt.repository.impl;

import com.matt.domain.courseV2.po.ChildrenMonthBodyPO;
import com.matt.foundation.DO.ChildListDO;
import com.matt.repository.base.BaseNativeSqlRepository;
import com.matt.repository.base.ChildStatureRepository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/21
 * *******************************
 */
@Service
public class ChildStatureRepositoryImpl extends BaseNativeSqlRepository implements ChildStatureRepository {
    @Override
    public List<ChildrenMonthBodyPO> findChildStature(String childrenId) {
        // 使用 String.format 直接拼接参数，避免参数绑定问题
        String sql = String.format("SELECT child_Id, " +
                "MAX(header) AS header, " +
                "MAX(weight) AS weight, " +
                "MAX(height) AS height, " +
                "month AS childrenMonth " +
                "FROM child_stature " +
                "WHERE child_Id = '%s' " +  // 直接拼接参数值
                "GROUP BY child_Id, month " +
                "ORDER BY month asc", childrenId);

        // 直接执行拼接好的SQL
        return sqlObjectList(sql, ChildrenMonthBodyPO.class);
    }
}
